package leetcode;

public class Q0028 {

    private boolean check(String haystack, String needle, int start) {
        for (int i = 0; i < needle.length(); i++) {
            if (haystack.charAt(i + start) != needle.charAt(i)) return false;
        }
        return true;
    }

    public int strStr(String haystack, String needle) {
        if (haystack.length() < needle.length()) return -1;
        for (int i = 0; i <= haystack.length() - needle.length(); i++) {
            if (check(haystack, needle, i)) return i;
        }
        return -1;
    }

    public static void main(String[] args) {
        Q0028 sl = new Q0028();
        String haystack = "sadbutsad";
        String needle = "sad";
//        String haystack = "leetcode";
//        String needle = "leeto";
        System.out.println(sl.strStr(haystack, needle));
    }
}
